﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SLBehaviourSystem
{
    public class LoopNode : DecoratorNode
    {
        protected int loopCount;
        private int curLoopedCount = 0;

        protected override void OnInitData()
        {
            loopCount = BehaviourData.GetInt(BehaviourArgsType.LoopCount);
        }

        protected override void OnExcute()
        {
            childNodeState = childNodes[0].Excute();
            if (childNodeState == BehaviourNodeState.Success)
            {
                curLoopedCount++;
            }
            else
            { }
            curNodeState = curLoopedCount >= loopCount ? BehaviourNodeState.Success : BehaviourNodeState.Running;
        }

        protected override void OnReset()
        {
            curLoopedCount = 0;
        }
    }
}
